/*
 * MIT License
 *
 * Copyright (c) 2024-2048 冰羽
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package cn.star.framework.excel.read.status;

import cn.star.framework.excel.core.RowType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import java.io.Serializable;
import java.util.List;
import lombok.Getter;
import lombok.Setter;

/**
 * 行状态 <br>
 *
 * @author zhaoweiping
 *     <p style='color: red'>Created on 2024-09-23 11:06:00
 * @since 3.0.0
 */
@JsonInclude(Include.NON_NULL)
public class RowStatus implements Serializable {

  /** 行号 */
  @Getter @Setter private Integer index;

  /** {@link RowType} */
  @Getter
  @Setter
  @JsonProperty(access = Access.WRITE_ONLY)
  private RowType type;

  /** 是否读取处理成功 */
  @Getter @Setter private Boolean success;

  /** 错误类型 */
  @Getter @Setter private String errorType;

  /** 读取处理时的错误信息 */
  @Getter @Setter private String message;

  /** 是否被外部读取了处理结果 */
  @Getter
  @Setter
  @JsonProperty(access = Access.WRITE_ONLY)
  private boolean externalReadStatus = false;

  /** 若存在关联表行信息, 则此为关联子行信息 */
  @Getter @Setter private List<RowStatus> children;

  public RowStatus() {}

  public RowStatus(Integer index, RowType type, boolean success) {
    this.index = index;
    this.type = type;
    this.success = success;
  }

  public RowStatus(Integer index, RowType type, boolean success, String message) {
    this.index = index;
    this.type = type;
    this.success = success;
    this.message = message;
  }

  public RowStatus(Integer index, RowType type, boolean success, String errorType, String message) {
    this.index = index;
    this.type = type;
    this.success = success;
    this.errorType = errorType;
    this.message = message;
  }

  /**
   * 请勿使用JsonProperty注解，否则不能将 {@link #success} 序列化返回
   *
   * <pre>&#064;JsonProperty(access = Access.WRITE_ONLY)</pre>
   *
   * @return
   */
  public boolean isSuccess() {
    return success != null && success;
  }
}
